package seqlist.leetcode;
// 倒数第K个节点
public class Offer_22 {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode fast = head,low = head;
        for (int i = 0; i < k; i++) {
            fast = fast.next;
        }
        // 此时再让low和fast同时向后移动，直到fast为空
        while (fast != null) {
            low = low.next;
            fast = fast.next;
        }
        return low;
    }
}
